<template>
  <div class="page-container">
    <SearchPanel @change="handleSearchPanelChange">
      <el-form
        ref="queryForm"
        class="query-more-form"
        size="mini"
        label-width="100px"
        :model="query"
      >
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="主体名称">
              <el-input
                v-model="query.unitName"
                class="search-ipt"
                placeholder="请输入主体名称"
                maxlength="255"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="5">
            <el-form-item label="主体类型">
              <el-select
                class="w-100"
                v-model="query.unitType"
                placeholder="请选择主体类型"
                clearable
                ><el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="5">
            <el-form-item label="检查部门">
              <el-input
                v-model="query.deptName"
                class="search-ipt"
                placeholder="请输入检查部门"
                maxlength="255"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="检查人员">
              <el-input
                v-model="query.nickName"
                class="search-ipt"
                placeholder="请输入检查人员"
                maxlength="255"
              />
            </el-form-item>
          </el-col>
          <el-col :span="3" class="btn-col">
            <el-button size="mini" class="search-btn" @click="select"
              >查询</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </SearchPanel>
    <div class="table-container">
      <div class="table-tools-panel table-flex-row">
        <div>
          <el-button class="flush-btn" size="mini" icon="el-icon-refresh"
            >刷新</el-button
          >
          <el-button
            :type="query.sourceCode == 1008 ? 'warning' : ''"
            size="medium"
            @click="changeTable(1008)"
            >镇街巡查</el-button
          >
          <el-button
            :type="query.sourceCode == 1009 ? 'warning' : ''"
            size="medium"
            @click="changeTable(1009)"
            >行政监管</el-button
          >
        </div>
        <div>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-set-up"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-share"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-printer"
          ></el-button>
        </div>
      </div>
      <div class="table-list-panel">
        <el-table
          v-loading="tableLoading"
          border
          size="small"
          :data="tableData"
          :height="isShow ? 'calc(100vh - 410px)' : 'calc(100vh - 335px)'"
          style="width: 100%"
        >
          <el-table-column type="selection" width="45" />
          <el-table-column
            prop="deptName"
            label="巡检部门名称"
            show-overflow-tooltip
          />
          <el-table-column
            prop="objCompanyName"
            label="巡检对象"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="objCompanyCode"
            label="社会信用代码"
            show-overflow-tooltip
          />
          <el-table-column
            prop="creatTime"
            label="检查时间"
            show-overflow-tooltip
          />
          <el-table-column
            prop="patrolUserNames"
            label="检查人员"
            show-overflow-tooltip
          />
          <el-table-column
            prop="inspectNumber"
            label="检查数量"
            width="70px"
            show-overflow-tooltip
          />
          <el-table-column
            prop="complianceNumber"
            label="合规数量"
            width="70px"
            show-overflow-tooltip
          />
          <el-table-column
            prop="violationNumber"
            label="违规数量"
            width="70px"
            show-overflow-tooltip
          />

          <el-table-column label="操作" width="160" fixed="right">
            <template slot-scope="scope">
              <el-button
                class="table-inner-btn"
                type="text"
                size="mini"
                @click="showpopup(scope.row)"
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-panel">
        <Pagination
          :total="query.total"
          :page.sync="query.pageNum"
          :limit.sync="query.pageSize"
          @pagination="select"
        />
      </div>
    </div>
    <popup-dialog
      :dialogVisible="dialogVisible"
      :obj="obj"
      @closeDialog="dialogVisible = false"
      ref="popupDialog1"
    />
  </div>
</template>

<script>
import SearchPanel from "@/components/SearchPanel";
import Pagination from "@/components/Pagination";
import { getList } from "@/api/system/inspectionRecord";
import popupDialog from "./components/popupDialog.vue";

export default {
  name: "CaseDealDispatch",
  components: {
    SearchPanel,
    Pagination,
    popupDialog
  },
  data() {
    return {
      popup: 0,
      options: [
        {
          value: "1",
          label: "法人"
        },
        {
          value: "2",
          label: "个人"
        }
      ],
      query: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
        sourceCode: 1008
      },
      tableLoading: false,
      tableData: [],
      isShow: true,
      dialogVisible: false,
      obj: {}
    };
  },
  created() {
    this.initData();
  },
  methods: {
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    initData() {
      this.select();
    },

    //
    changeTable(val) {
      this.query.sourceCode = val;
      this.select();
    },

    select() {
      this.tableLoading = true;
      getList(this.query)
        .then(result => {
          this.tableLoading = false;
          this.query.total = result.total;
          this.tableData = result.rows;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    showpopup(row) {
      // this.obj = row;
      // this.$refs.popupDialog1.select();
      // this.dialogVisible = true;
      let href_url = location.href;
      let url = href_url.match(/access_token=(\S*)&expireTime/)[1];
      let addressUrl = `${detailsUrl}/km/review/km_review_main/kmReviewMain.do?access_token=${url}&method=view&fdId=${
        row.id
      }`;
      window.open(addressUrl);
    }
  }
};
</script>

<style lang="scss" scoped></style>
